<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<PagedList<Pulog.Models.Post>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <h2>EditList</h2>

    <table>
        <tr>
            <th></th>
            <th>
                postID
            </th>
            <th>
                title
            </th>
            <th>
                pubTime
            </th>
            <th>
                authorID
            </th>
            <th>
                views
            </th>
            <th>
                property
            </th>
            <th>
                categoryID
            </th>
            <th>
                sticky
            </th>

            <th>
                slug
            </th>
        </tr>

    <% foreach (var item in Model) { %>
    
        <tr>
            <td>
                <%= Html.ActionLink("Edit", "Edit", new { id=item.postID }) %> |
                <%--<%= Html.ActionLink("Delete", "Delete", new { id=item.postID })%>--%>
                <%--<input id="hidPostID" type="hidden" value="item.postID" />--%>
                <a id="DeletePost" href="javascript:DeletePost(<%=item.postID %>)">Delete</a>
            </td>
            <td>
                <%= Html.Encode(item.postID) %>
            </td>
            <td>
                <%= Html.Encode(item.title) %>
            </td>
            <td>
                <%= Html.Encode(String.Format("{0:g}", item.pubTime)) %>
            </td>
            <td>
                <%= Html.Encode(item.authorID) %>
            </td>
            <td>
                <%= Html.Encode(item.views) %>
            </td>
            <td>
                <%= Html.Encode(item.property) %>
            </td>
            <td>
                <%= Html.Encode(item.categoryID) %>
            </td>
            <td>
                <%= Html.Encode(item.sticky) %>
            </td> 
            <td>
                <%= Html.Encode(item.slug) %>
            </td>
        </tr>
    <% } %>

    </table>

    <div id="paging">
        <%if (Model.IsPreviousPage)
          { %>
            <%=Html.ActionLink("Newer Posts", "Edit", new { page = ViewData.Model.PageIndex - 1 })%>&nbsp;&nbsp;
        <%} %>
        <%if (Model.IsNextPage)
          { %>
            <%=Html.ActionLink("Older Posts", "Edit", new { page = ViewData.Model.PageIndex + 1 })%>
        <%} %>
    </div>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
//    $(document).ready(function() {
//            $("#DeletePost").click(function() {
//                var c = $('#hidPostID').attr("Value");
//                $.ajax({
//                    type: "POST",
//                    data: c,
//                    url: "<%=ResolveUrl("~/Posts/Delete/") %>",
//                    success: function(){
//                        alert('y');
//                    },
//                    eror: function() {
//                        alert('err');
//                    },
//                    complete: function(){
//                        alert("Complete");
//                    }
//                });
//            });
    //        });
    function DeletePost(id)
    {
        $.ajax({
            type: "POST",
            data: "id="+id,
            dataType: "json",
            url: "<%=ResolveUrl("~/Posts/Delete/") %>",
            success: function(){
                alert('y');
            },
            eror: function() {
                alert('err');
            },
            complete: function(){
                alert("Complete");
                window.location.reload();
            }
        });
    }
</script>
</asp:Content>

